
package osifbot;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jibble.pircbot.IrcException;
import org.jibble.pircbot.NickAlreadyInUseException;

/**
 *
 *
 * 
 *    OSIFBOT
 *    Copyright (C) 2013  etchner jorge@devetch.com
 *
 *    This program is free software: you can  redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class InterfazIRC {
    private IRC conexion;
    private String nick;
    private String name;
    private String password;
    private String host;
    private int puerto;

    public InterfazIRC(String nick, String name, String password, String host, int puerto, InterfazBBDD bbdd ,String url) {
        this.nick = nick;
        this.name = name;
        this.password = password;   
        this.host = host;
        this.puerto = puerto;
        if(name != null) {
            conexion = new IRC(nick,name,bbdd, url);
        }
        else {
            conexion = new IRC(nick,bbdd, url);
        }
        
    }
    
    public InterfazIRC(String nick, String name, String password, String host, InterfazBBDD bbdd,String url) {
        this.nick = nick;
        this.name = name;
        this.password = password;        ;
        this.host = host;
        this.puerto = 6667;
        if(name != null) {
            conexion = new IRC(nick,name,bbdd, url);
        }
        else {
            conexion = new IRC(nick,bbdd, url);
        }                
    }    

    
    public void conectar(){
        try {
            if(password == null) {
                conexion.connect(host, puerto);
            }
            else {
                conexion.connect(host, puerto, password);
                conexion.identify(password);
            }
        } catch (IOException ex) {
            Logger.getLogger(InterfazIRC.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IrcException ex) {
            Logger.getLogger(InterfazIRC.class.getName()).log(Level.SEVERE, null, ex);
        } 
        
    }
    
    public void joinChannel(String channel){
        this.conexion.joinChannel(channel);    
    }
    
    public void joinChannel(String channel, String password){
        this.conexion.joinChannel(channel, password);    
    }    
    
    public void setVerbose(boolean verbose){
        this.conexion.setVerbose(verbose);
    }
    
    public void desconectar(){
        conexion.disconnect();
    }
    
    
    
    
}
